import { storage } from '@/config'
import cookie from 'js-cookie'

/**
 * @author fht 863772124@qq.com
 * @description 获取布局
 */
export function getLayout() {
  if (storage) {
    if ('localStorage' === storage) {
      return localStorage.getItem('layoutName')
    } else if ('sessionStorage' === storage) {
      return sessionStorage.getItem('layoutName')
    } else if ('cookie' === storage) {
      return cookie.get('layoutName')
    } else {
      return localStorage.getItem('layoutName')
    }
  } else {
    return localStorage.getItem('layoutName')
  }
}

export function setLayout(layout) {
  if (storage) {
    if ('localStorage' === storage) {
      return localStorage.setItem('layoutName', layout)
    } else if ('sessionStorage' === storage) {
      return sessionStorage.setItem('layoutName', layout)
    } else if ('cookie' === storage) {
      return cookie.set('layoutName', layout)
    } else {
      return localStorage.setItem('layoutName', layout)
    }
  } else {
    return localStorage.setItem('layoutName', layout)
  }
}

//移除accessToken
export function removelayout() {
  if (storage) {
    if ('localStorage' === storage) {
      return localStorage.removeItem('layoutName')
    } else if ('sessionStorage' === storage) {
      return sessionStorage.clear()
    } else if ('cookie' === storage) {
      return cookie.remove('layoutName')
    } else {
      return localStorage.removeItem('layoutName')
    }
  } else {
    return localStorage.removeItem('layoutName')
  }
}
